package org.fast.project.web.config;

import org.fast.project.web.advice.GlobalRequestInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author : lilith·bristol
 * @program : spring-web-archetype-config
 * @description : 拦截器配置
 * @date : 2020-04-20 00:57
 **/
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    private final GlobalRequestInterceptor globalRequestInterceptor;

    public InterceptorConfig(GlobalRequestInterceptor globalRequestInterceptor) {
        this.globalRequestInterceptor = globalRequestInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器
        registry.addWebRequestInterceptor(globalRequestInterceptor)
                // 拦截所有请求
                .addPathPatterns("/**");
    }
}
